package com.kejiguan.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.ExhibitionNeItem;

import java.util.List;

/**
 * Created by apple on 16/3/13.
 */
public class DisplaySettingItemAdapter extends RecyclerView.Adapter<DisplaySettingItemVH> {

    private Context mContext;
    private List<ExhibitionNeItem> presenterItems;
    private LayoutInflater mInflater;
    private View.OnClickListener onClickListener;
    private View.OnLongClickListener onLongClickListener;


    public DisplaySettingItemAdapter(Context mContext, List<ExhibitionNeItem> presenterItems) {
        this.mContext = mContext;
        this.presenterItems = presenterItems;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public DisplaySettingItemVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.fragment_display_setting_item_layout, null);
        return new DisplaySettingItemVH(itemView);
    }

    @Override
    public void onBindViewHolder(DisplaySettingItemVH holder, int position) {
        ExhibitionNeItem displayItem=presenterItems.get(position);
        holder.nameInfoView.setText(displayItem.getExhibitionName());
        holder.ipInfoView.setText(displayItem.getExhibitionId());
//        holder.macInfoView.setText(displayItem.getMac());

        holder.itemView.setTag(R.id.recyclerview_item_position,position);
        if (null!=onClickListener)
        {
            holder.itemView.setOnClickListener(onClickListener);
        }
        if (null!=onLongClickListener)
        {
            holder.itemView.setOnLongClickListener(onLongClickListener);
        }
    }

    @Override
    public int getItemCount() {
        if (null == presenterItems) {
            return 0;
        } else {
            return presenterItems.size();
        }

    }


    public ExhibitionNeItem getNeItem(int position)
    {
        if (null!=presenterItems)
        {
            if (position>=presenterItems.size())
            {
                return null;
            }else
            {
                return presenterItems.get(position);
            }

        }else
        {
            return null;
        }
    }

    public void setPresenterItems(List<ExhibitionNeItem> presenterItems) {
        this.presenterItems = presenterItems;
        notifyDataSetChanged();
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public void setOnLongClickListener(View.OnLongClickListener onLongClickListener) {
        this.onLongClickListener = onLongClickListener;
    }
}
